﻿using BigEgg.Framework.Applications.ViewModels;
using BigEgg.Framework.Foundation;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Xml.Serialization;

namespace FMStudio.Documents.TemplateDocument.Models
{
    public abstract class TemplateContent : DataModel, IDataErrorInfo
    {
        #region Fields
        /// <summary>
        /// The instance of a <see cref="DataErrorInfoSupport"/>
        /// </summary>
        protected readonly DataErrorInfoSupport dataErrorInfoSupport;
        private ObservableCollection<Item> items;
        #endregion


        public TemplateContent()
        {
            this.dataErrorInfoSupport = new DataErrorInfoSupport(this);

            this.items = new ObservableCollection<Item>();

            AddWeakEventListener(this.items, ItemsCollectionChanged);
        }


        #region Implament IDataErrorInfo interface
        string IDataErrorInfo.Error { get { return this.dataErrorInfoSupport.Error; } }

        string IDataErrorInfo.this[string columnName] { get { return this.dataErrorInfoSupport[columnName]; } }
        #endregion

        #region Properties
        /// <summary>
        /// The items contains in the folder.
        /// </summary>
        [XmlElement(Type = typeof(Folder)),
         XmlElement(Type = typeof(ProjectItem))]
        public ObservableCollection<Item> Items { get { return this.items; } }
        #endregion

        #region Methods
        #region Private Methods
        private void ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            RaisePropertyChanged("Items");
        }
        #endregion
        #endregion

    }
}
